<?php


namespace app\common\model;


class ProductSkuModel extends CommonModel
{
    protected $name = 'product_sku';
    //    public function xxxxxInfo(): \think\model\relation\BelongsTo
    //    {
    //        return $this->belongsTo(MediaModel::class, 'media_id', 'id');
    //    }

    //    public function xxxxxInfo()
    //    {
    //        return $this->belongsToMany(RoleModel::class, GroupRoleModel::class,'role_id','group_id');
    //    }
    public static function deductStock($skuModel, $countTotal): bool
    {
        /**
         * $skuModel->getData('stock')
         * $skuModel->getData('sales')
         * $skuModel->getData('virtual_sales')
         * 可用库存 $skuModel->getData('stock') - $skuModel->getData('sales') - $skuModel->getData('virtual_sales')
         */
        if ($skuModel->getData('stock') - $skuModel->getData('sales') - $skuModel->getData('virtual_sales') <= 0) {
            return false;
        }
        $skuModel->sales += $countTotal;
        $skuModel->save();
        return true;
    }
}